<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>浏览页面</title>
    <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/app/admin/admin/css/reset.css"/>
</head>
<body class="pear-container">


<div class="layui-card">
    <div class="layui-card-body">

        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this" permission="app.dingtalk.admin.setting.save">钉钉设置</li>
                <li permission="app.dingtalk.admin.setting.test">演示测试</li>
            </ul>
            <div class="layui-tab-content">

                <!-- 钉钉设置 -->
                <div class="layui-tab-item  layui-show">

                    <form class="layui-form" onsubmit="return false" lay-filter="setting" style="width: 520px">
                        <div class="layui-form-item">
                            <label class="layui-form-label">访问令牌</label>
                            <div class="layui-input-block">
                                <input type="text" name="AccessToken" required lay-verify="required" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">加签</label>
                            <div class="layui-input-block">
                                <input type="text" name="Secret" required lay-verify="required" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="saveSetting">
                                    保存设置
                                </button>
                            </div>
                        </div>
                    </form>

                </div>

                <div class="layui-tab-item">

                    <form class="layui-form" onsubmit="return false" lay-filter="test" style="width: 520px">
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">测试标题</label>
                            <div class="layui-input-block">
                                <input type="text" name="Title" placeholder="请输入内容" class="layui-input"></input>
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">消息内容</label>
                            <div class="layui-input-block">
                                <textarea name="Content" placeholder="请输入内容" class="layui-textarea"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="submit" class="pear-btn pear-btn-danger pear-btn-md" lay-submit="" lay-filter="sendMail">
                                    机器人测试
                                </button>
                            </div>
                        </div>
                    </form>

                </div>

            </div>
        </div>

    </div>
</div>

<script src="/app/admin/component/layui/layui.js"></script>
<script src="/app/admin/component/pear/pear.js"></script>
<script src="/app/admin/admin/js/common.js"></script>

<!-- 测试 -->
<script>
    layui.use(["form", "popup"], function(){
        let form = layui.form;
        let $ = layui.jquery;

        $.ajax({
            url: "/app/dingtalk/admin/setting/get",
            success: function (res) {
                if (res.code) {
                    return layui.popup.failure(res.msg);
                }
                form.val("setting", res.data);
                form.val("test", res.data);
            }
        });

        // 保存设置
        form.on("submit(saveSetting)", function(data){
            $.ajax({
                url: "/app/dingtalk/admin/setting/save",
                dataType: "json",
                type: "POST",
                data: data.field,
                success: function (res) {
                    if (res.code) {
                        return layui.popup.failure(res.msg);
                    }
                    form.val("test", data.field);
                    return layui.popup.success("操作成功");
                }
            });
            return false;
        });

        // 测试表单
        form.on("submit(sendMail)", function(data){
            $.ajax({
                url: "/app/dingtalk/admin/setting/test",
                dataType: "json",
                type: "POST",
                data: data.field,
                success: function (res) {
                    if (res.code) {
                        return layui.popup.failure(res.msg);
                    }
                    return layui.popup.success("操作成功");
                }
            });
            return false;
        });
    });
</script>

<style>

    .layui-input-block {
        margin-left: 150px;
    }

    .layui-form-label {
        width:120px;
    }

</style>
</body>
</html>

